package com.gw.detail.controllor.detail;

import com.gw.detail.domain.Anprall;
import com.gw.detail.service.IAnprallService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 人员的单个碰撞Controller
 *
 * @author WangBin
 * @date 2021-04-30
 */
@RestController
@RequestMapping("/detail/anprall")
public class AnprallController extends BaseController {
    @Autowired
    private IAnprallService anprallService;

    /**
     * 查询人员的单个碰撞列表
     */
    @PreAuthorize("@ss.hasPermi('detail:anprall:list')")
    @GetMapping("/list")
    public TableDataInfo list(Anprall anprall) {
        startPage();
        List<Anprall> list = anprallService.selectAnprallList(anprall);
        return getDataTable(list);
    }

    /**
     * 导出人员的单个碰撞列表
     */
    @PreAuthorize("@ss.hasPermi('detail:anprall:export')")
    @Log(title = "人员的单个碰撞", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Anprall anprall) {
        List<Anprall> list = anprallService.selectAnprallList(anprall);
        ExcelUtil<Anprall> util = new ExcelUtil<Anprall>(Anprall.class);
        return util.exportExcel(list, "人员的单个碰撞数据");
    }

    /**
     * 获取人员的单个碰撞详细信息
     */
    @PreAuthorize("@ss.hasPermi('detail:anprall:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(anprallService.selectAnprallById(id));
    }

    /**
     * 新增人员的单个碰撞
     */
    @PreAuthorize("@ss.hasPermi('detail:anprall:add')")
    @Log(title = "人员的单个碰撞", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Anprall anprall) {
        return toAjax(anprallService.insertAnprall(anprall));
    }

    /**
     * 修改人员的单个碰撞
     */
    @PreAuthorize("@ss.hasPermi('detail:anprall:edit')")
    @Log(title = "人员的单个碰撞", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Anprall anprall) {
        return toAjax(anprallService.updateAnprall(anprall));
    }

    /**
     * 删除人员的单个碰撞
     */
    @PreAuthorize("@ss.hasPermi('detail:anprall:remove')")
    @Log(title = "人员的单个碰撞", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(anprallService.deleteAnprallByIds(ids));
    }
}
